<template>
  <div class="app-container">
    <div class="filter-container" style="padding-bottom:20px;">
      <el-input v-model="listQuery.keywords" placeholder="名称 备注" style="width: 400px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-date-picker
        v-model="listQuery.datetimeStart"
        type="datetime"
        placeholder="选择日期时间">
      </el-date-picker>
      <span class="demonstration">-</span>
      <el-date-picker
        v-model="listQuery.datetimeEnd"
        type="datetime"
        placeholder="选择日期时间">
      </el-date-picker>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-document">
        导出excel
      </el-button>
    </div>

    <el-table
      :data="list"
      v-loading="listLoading"
      style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="名称">
              <span>{{ props.row.name }}</span>
            </el-form-item >
            <el-form-item label="SN">
              <span>{{ props.row.sn }}</span>
            </el-form-item >
            <el-form-item label="封装">
              <span>{{ props.row.package }}</span>
            </el-form-item >
            <el-form-item label="价格">
              <span>{{ props.row.price }}</span>
            </el-form-item >
            <el-form-item label="库存">
              <span>{{ props.row.stock }}</span>
            </el-form-item >
            <el-form-item label="位置">
                <span>{{ props.row.position }}</span>
            </el-form-item >
            <el-form-item label="项目">
                <span>{{ props.row.project }}</span>
            </el-form-item >
            <el-form-item label="产品">
                <span>{{ props.row.product }}</span>
            </el-form-item >
            <el-form-item label="供货商">
                <span>{{ props.row.supplier }}</span>
            </el-form-item >
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        label="名称"
        prop="name">
      </el-table-column>
      <el-table-column
        label="出库数"
        prop="count">
      </el-table-column>
      <el-table-column
        label="备注"
        prop="note">
      </el-table-column>
      <el-table-column
        label="出库时间"
        prop="created_time">
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />

  </div>
</template>

<script>

import { electronicOutStockLogList } from '@/api/electronic'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'find',
  components: { Pagination },
  directives: { waves },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      listLoading: true,
      total: 10,
      selectRow: null,
      listQuery: {
        keywords: null,
        page: 1,
        limit: 20,
        datetimeStart: '',
        datetimeEnd: ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      electronicOutStockLogList(this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data.items
        this.total = response.data.total
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },
  }
}
</script>

<style>
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

